package com.wydpp.config;

import com.wydpp.gb28181.bean.SipPlatform;
import com.wydpp.properties.SipServerProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@Configuration
public class BeanConfig {

    @Autowired
    private SipServerProperties sipServerProperties;


    @Bean
    public SipPlatform sipPlatform() {
        SipPlatform sipPlatform = new SipPlatform();
        sipPlatform.setServerGBId(sipServerProperties.getId());
        sipPlatform.setServerGBDomain(sipServerProperties.getDomain());
        sipPlatform.setServerIP(sipServerProperties.getIp());
        sipPlatform.setServerPort(sipServerProperties.getPort());
        sipPlatform.setPassword(sipServerProperties.getPassword());
        //使用UDP协议
        sipPlatform.setTransport("UDP");
        //注册有效期1个小时
        sipPlatform.setExpires("3600");
        sipPlatform.setKeepTimeout(sipServerProperties.getKeepaliveTimeOut());
        return sipPlatform;
    }

    @Bean
    public ThreadPoolTaskScheduler threadPoolTaskScheduler(){
        ThreadPoolTaskScheduler threadPoolTaskScheduler
                = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setPoolSize(5);
        threadPoolTaskScheduler.setThreadNamePrefix(
                "ThreadPoolTaskScheduler");
        return threadPoolTaskScheduler;
    }

}
